home *** CD-ROM | disk | FTP | other *** search
- Path: diku.dk!diku2471
- From: diku2471@diku.dk (ASGER ALSTRUP NIELSEN)
- Newsgroups: comp.sys.cbm
- Subject: Re: Programming (assembler) Question
- Date: 29 Feb 1996 11:19:54 GMT
- Organization: Department of Computer Science, U of Copenhagen
- Sender: diku2471@alvis.diku.dk
- Message-ID: <4h424q$613@odin.diku.dk>
- References: <0lB_Eq200bkw1YeEk0@andrew.cmu.edu>
- NNTP-Posting-Host: odin.diku.dk
- X-Newsreader: NN version 6.5.0 #13
-
- William Nolan <wnolan+@andrew.cmu.edu> writes:
-
- >Okay, here's my problem. In a lot of my Turbo Assembler programs, I
- >use the * directive several times to place data at the appropriate
- >locations in memory (ie sprite data, character set data, etc). When I
- >compile and run under Turbo Assembler, these programs work fine, since
- >I assume that as it assembles, TA puts the data in the right places in
- >memory. But when I compile to object code and save that to disk, the
- >often programs stop working. So I was wondering what to do about
- >this? Any ideas? Thanks!
-
- You've ran into The First Limitation of Turbo Assembler.
-
- It's not possible to use the *=adress statement if you want valid
- object-files.
- The reason lies in the binary format used by commodore. In this native
- object-format used by Turbo Assembler, it is not possible to have more
- than one starting address of any program.
- You can partly solve the problem by splitting your source-file, but
- this is not always an option because of global variables which have to
- be defined in all source-files, which isn't easy because you cannot
- include files in TA.
- The usual solution is to compile to memory and save directly from memory
- using a monitor. Some enhanced versions of TA can save memory directly
- with some <- command.
- If your program assembles to areas which ruin something (like TA itself),
- you should get a REU (ram expansion unit) and use a REU-version of TA.
- Alternatively, you can use the .offs directive, which causes the object
- code to be place at a different address in memory eventhough it's
- compiled as if it was placed at another place:
-
- * = $2000
- .offs $1000
-
- loop lda $d012
- sta $d020
- jmp loop
-
- This will be assemblied and placed at $3000 ($2000+$1000), but the
- jmp-statement will be assembled as jmp $2000.
- The .offs statement is general, so if you do:
-
- * = $2000
- .offs $1000
-
- l1 jmp l1
-
- * = $2100
-
- l2 jmp l2
-
- you will end up with assembled code at $3000 and $3100.
-
- This issue is general to most assemblers on the C64. Some fix the
- problem correctly and generate several object files where each
- correspond to a *=address block. On other architechtures, the
- problem is addresses by the linker, but I have not seen such a
- thing for the C64 yet.
-
- From time to time, formats for allowing relocatable code is dis-
- cussed here, and various formats have been proposed. Some of those
- formats could solve this, but I have yet to see an implementation.
-
- Meanwhile, go back and reconsider your code. Why do you use the
- *=address statement more than once? Why don't you just load your
- data instead of using .data statements. This will save space
- and will speed up your compile. Already, you must use a separate
- file for the music, don't you?
- Serious demo-hackers don't mess up their sourcefiles with charsets
- and sprites. If they do, they put it right after the code, and code
- a small movement-routine that places the data the appropriate places.
- This approach allows you to do your entire demo in one piece, which
- can be packed directly by your favourite packer. But once again,
- keep the graphics out of the source!
-
- If you need control of pages, consider putting the timecritical code
- in the beginning of your program.
-
- If you have other reasons, you're screwed.
-
- Greets,
-
- Asger Alstrup
-